// miniprogram/devTools/chbqb/chbqb.js
import {
  chbqbDetail,
  webview
} from '../../router'
Page({

  data: {
    bqbList: [],
    github: 'https://github.com/zhaoolee/ChineseBQB'
  },
  onLoad: function (options) {
    this.getBqbData()
  },
  onShareAppMessage: function () {

  },
  onShareTimeline() {

  },
  getBqbData() {
    wx.showLoading({
      title: '加载中'
    })
    wx.cloud.callFunction({
      name: 'wanandroid',
      data: {
        action: "chbqb"
      }
    }).then(res => {
      console.log(res)
      wx.hideLoading()
      let bqbList = res.result
      this.setData({
        bqbList
      })
    }, err => {
      wx.hideLoading()
      console.error(err)
    })
  },
  onMenuClick(event) {
    console.log(event)
    let bqbData = event.currentTarget.dataset.menu
    wx.navigateTo({
      url: chbqbDetail + "?bqbData=" + encodeURI(JSON.stringify(bqbData))
    })
  },
  onGithubClick() {
    let github = this.data.github
    wx.navigateTo({
      url: webview + "?url=" + github
    })
  },
  // 复制文字监听
  copyText: function (e) {
    // console.log(e)
    let text = e.currentTarget.dataset.text
    if (typeof text == 'object')
      text = text[0]
    console.log("copyText", text)
    wx.setClipboardData({
      data: text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功',
              icon: 'none'
            })
          }
        })
      }
    })
  },
})